package com.fengwk.resource.config;

import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Configuration;

import com.fengwk.support.spring.boot.config.AbstractTomcatEmbeddedServletContainerFactoryConfig;


@Configuration
public class TomcatEmbeddedServletContainerFactoryConfig extends AbstractTomcatEmbeddedServletContainerFactoryConfig {

	// tomcatEmbedded这段代码是为了解决,上传文件大于10M出现连接重置的问题 此异常内容GlobalException也捕获不到
	@Override
	protected EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() {
		TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) super.createEmbeddedServletContainerFactory();
		tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
			@Override
			public void customize(Connector connector) {
				if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
	                ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
	            }
			}
		});
		return tomcat;
	}

}
